<template>
  <el-dialog
    :title="title"
    :visible="showDialog"
    width="800px"
    center
    @close="btnCancel"
  >
    <template #title>
      <el-row type="flex" justify="start">
        <span class="title">{{ title }}</span>
      </el-row>
    </template>
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="文章标题" prop="title">
        <el-input v-model="ruleForm.title" placeholder="请输入文章标签" />
      </el-form-item>
      <el-form-item class="editorform" label="文章内容" prop="articleBody">
        <QuillEditor ref="markdeitor" />
      </el-form-item>
      <el-form-item label="视频地址">
        <el-input v-model="ruleForm.videoURL" placeholder="请输入视频地址" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-row type="flex" justify="end">
        <el-button @click="btnCancel">取 消</el-button>
        <el-button type="primary" @click="btnOk">确 定</el-button>
      </el-row>

    </span>
  </el-dialog>
</template>

<script>
// import { add } from '@/api/hmmm/directorys.js'
import QuillEditor from './quill-editor.vue'
export default {
  components: {
    QuillEditor
  },
  props: {
    showDialog: {
      type: Boolean,
      require: true
    },
    sympleDate: {
      require: true
    }
  },
  data() {
    return {
      rules: {
        title: [
          { required: true, message: '请输入文章标题', trigger: 'blur' }
        ],
        articleBody: [
          { required: true, message: '请输入文章内容', trigger: 'input' }
        ] },
      ruleForm: {
        id: null,
        title: '',
        articleBody: '',
        videoURL: ''
      },
      title: '新增文章'

    }
  },
  methods: {
    btnCancel() {
      this.$refs.ruleForm.resetFields()//   validateField
      this.$refs.markdeitor.content = ''
      this.ruleForm.videoURL = ''
      this.$emit('update:showDialog', false)
      setTimeout(() => {
        this.title = '新增目录'
      }, 200)
    },
    btnOk() {
      this.$refs.ruleForm.validate(async isOk => {
        this.ruleForm.articleBody = this.$refs.markdeitor.content

        if (this.ruleForm.articleBody && this.ruleForm.title) {
          this.$emit('addSub', this.ruleForm)// 通知父组件更新信息
        }
      })
    },
    updata(data) {
    //   console.log(data, 'zi组件')
      this.ruleForm.articleBody = data
      setTimeout(() => {
        this.$refs.markdeitor.bodydata(data)
      }, 0)
    }
  }
}
</script>

<style scoped lang='scss'>
.title{
    color: white;
    font-size: 20px;
}
::v-deep{
.el-input--medium {
    width: 660px;
}
.el-dialog__body{
   padding: 25px 15px 30px
}
.el-form-item__label{
    width: 80px!important;
}
.el-form-item__content{
margin-left: 80px!important;
}
.el-input__inner{
    height: 32px!important;

}
.editorform{
    height: 250px;
}

}

</style>
